**********************************************************
******** The Bridge Project, Final Analysis File *********
******* Butikofer, Loken, and Willen (2022) **************
**********************************************************
* Date: Feb 16, 2022
* Stata version: 15.1
**********************************************************
version 15
set seed 888888
log using BLW_Bridge_2022_Analysis, replace 

***************************************************************
* Setting directory. Note: Replace X with actual local path directory prior to running. 
	global path_base 	"X\Temp"
	global output 		"X\Results"
	global path_adv 	"X\Analysis Data"
***************************************************************


*********************
*********************
** MAIN MANUSCRIPT **
*********************
*********************


****************
* MAIN FIGURES ***
****************

	************
	* Figure 1 *
	************
	{
		eststo clear
		use "$path_base\RegSamp", clear	
			
			foreach xvar of varlist SEKwork DKwork {
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store General
				coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
				graph export "$output\Fig1_`xvar'.png",  replace
				}	
				
			foreach xvar of varlist DKtotwage Totwage SEKtotwage  {
				replace `xvar'=`xvar'/1000
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store General
				coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
				(horizontal) nogrid) ylabel(-20(20)60)		
				graph export "$output\Fig1_`xvar'.png",  replace
				}	
	}


	************
	* Figure 2 *   
	************
	{
		**********
		* Pooled *
		**********
		{
		eststo clear
			use "$path_base\RegSamp3", clear
			gen live99L=Lan if year==1999
			bysort P0950_LopNr_PersonNr: egen insampL=max(live99L)
			keep if kommun==1280 | Lan==7 | Lan==10 | Lan==13 | Lan==6 | Lan==8
			gen age99=Alder-(year-1999) 
			gen Age=Alder
			
			foreach xvar of varlist DKwork {
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Baseline
				eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
				estimates store Covariates
				eststo: xi: reghdfe `xvar' Y1997-Y2008 if ((Lan==insampL & age99>18) | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
				estimates store ExcludingEntrants
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
				estimates store IncludingFEs
				
				coefplot (Baseline, mcolor(black) ciopts(lcolor(black))) (Covariates, mcolor(bluishgray) ciopts(lcolor(bluishgray))) (ExcludingEntrants, mcolor(gs7) ciopts(lcolor(gs7))) (IncludingFEs, mcolor(gs12) ciopts(lcolor(gs12))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
				graph export "$output\Fig2_`xvar'.png",  replace
				}	
				
			foreach xvar of varlist Totwage  {
				replace `xvar'=`xvar'/1000
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Baseline
				eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
				estimates store Covariates
				eststo: xi: reghdfe `xvar' Y1997-Y2008 if ((Lan==insampL & age99>18) | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
				estimates store ExcludingEntrants
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
				estimates store IncludingFEs
				coefplot (Baseline, mcolor(black) ciopts(lcolor(black))) (Covariates, mcolor(bluishgray) ciopts(lcolor(bluishgray))) (ExcludingEntrants, mcolor(gs7) ciopts(lcolor(gs7))) (IncludingFEs, mcolor(gs12) ciopts(lcolor(gs12))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
				(horizontal) nogrid) ylabel(-20(20)60)		
				graph export "$output\Fig2_`xvar'.png",  replace
				}	
		}
		
		*********
		* Males *
		*********
		{
		eststo clear
			use "$path_base\RegSamp3", clear
			gen live99L=Lan if year==1999
			bysort P0950_LopNr_PersonNr: egen insampL=max(live99L)
			keep if kommun==1280 | Lan==7 | Lan==10 | Lan==13 | Lan==6 | Lan==8
			gen age99=Alder-(year-1999) 
			gen Age=Alder

		keep if Female==0
			foreach xvar of varlist DKwork {
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Baseline
				eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
				estimates store Covariates
				eststo: xi: reghdfe `xvar' Y1997-Y2008 if (Lan==insampL & age99>18 | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
				estimates store ExcludingEntrants
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
				estimates store IncludingFEs
				coefplot (Baseline, mcolor(black) ciopts(lcolor(black))) (Covariates, mcolor(bluishgray) ciopts(lcolor(bluishgray))) (ExcludingEntrants, mcolor(gs7) ciopts(lcolor(gs7))) (IncludingFEs, mcolor(gs12) ciopts(lcolor(gs12))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
				graph export "$output\Fig2_`xvar'_M.png",  replace
				}	
			foreach xvar of varlist Totwage  {
				replace `xvar'=`xvar'/1000
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Baseline
				eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
				estimates store Covariates
				eststo: xi: reghdfe `xvar' Y1997-Y2008 if (Lan==insampL & age99>18 | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
				estimates store ExcludingEntrants
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
				estimates store IncludingFEs
				coefplot (Baseline, mcolor(black) ciopts(lcolor(black))) (Covariates, mcolor(bluishgray) ciopts(lcolor(bluishgray))) (ExcludingEntrants, mcolor(gs7) ciopts(lcolor(gs7))) (IncludingFEs, mcolor(gs12) ciopts(lcolor(gs12))), keep(Y*) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
				(horizontal) nogrid) ylabel(-20(20)60)		
				graph export "$output\Fig2_`xvar'_M.png",  replace
				}	
		}
		
		***********
		* Females *
		***********
		{
		eststo clear
			use "$path_base\RegSamp3", clear
			gen live99L=Lan if year==1999
			bysort P0950_LopNr_PersonNr: egen insampL=max(live99L)
			keep if kommun==1280 | Lan==7 | Lan==10 | Lan==13 | Lan==6 | Lan==8
			gen age99=Alder-(year-1999) 
			gen Age=Alder

		keep if Female==1
			foreach xvar of varlist DKwork {
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Baseline
				eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
				estimates store Covariates
				eststo: xi: reghdfe `xvar' Y1997-Y2008 if (Lan==insampL & age99>18 | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
				estimates store ExcludingEntrants
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
				estimates store IncludingFEs
				coefplot (Baseline, mcolor(black) ciopts(lcolor(black))) (Covariates, mcolor(bluishgray) ciopts(lcolor(bluishgray))) (ExcludingEntrants, mcolor(gs7) ciopts(lcolor(gs7))) (IncludingFEs, mcolor(gs12) ciopts(lcolor(gs12))), keep(Y*) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
				graph export "$output\Fig2_`xvar'_F.png",  replace
				}	
			foreach xvar of varlist Totwage  {
				replace `xvar'=`xvar'/1000
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Baseline
				eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
				estimates store Covariates
				eststo: xi: reghdfe `xvar' Y1997-Y2008 if (Lan==insampL & age99>18 | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
				estimates store ExcludingEntrants
				eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
				estimates store IncludingFEs
				coefplot (Baseline, mcolor(black) ciopts(lcolor(black))) (Covariates, mcolor(bluishgray) ciopts(lcolor(bluishgray))) (ExcludingEntrants, mcolor(gs7) ciopts(lcolor(gs7))) (IncludingFEs, mcolor(gs12) ciopts(lcolor(gs12))), keep(Y*) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
				(horizontal) nogrid) ylabel(-20(20)60)		
				graph export "$output\Fig2_`xvar'_F.png",  replace
				}	
		}
	}


	************
	* Figure 3 *
	************
	{
	* Prepping the data 
	
		eststo clear
		use "$path_base\RegSamp", clear	
		compress
		
		gen Kon=1 if Female==0
		replace Kon=2 if Female==1
		
		* i. Identifying couples
		bysort P0950_LopNr_FamId year: egen mar=sum(married)
		keep if mar==2 // keeping only families with two pepople that are married
		keep if married==1 // keeping the parents
		bysort P0950_LopNr_FamId year: egen coup=sum(Kon)
		keep if coup==3 // keeping only heterosexual couples as we are exploring the gender gap
			
		* ii. Obtaining outcomes 
		foreach outc of varlist DKwork Totwage { 
		gen `outc'_Fem=`outc' if Female==1
		replace `outc'_Fem=0 if Female==0
		bysort P0950_LopNr_FamId year: egen F_`outc'=max(`outc'_Fem)
		replace `outc'=`outc'-F_`outc'
		}
		
		* iii. Only need one from each coulpes as outcomes are couple differences 
		keep if Female==0
		save "$path_base\Couples", replace 
		
		
	* Running the regressions 
	
	use "$path_base\Couples", clear 
		{
		
		foreach xvar of varlist DKwork {
			eststo: xi: reg `xvar' Y1997-Y2008 i.year i.Treat i.kommun i.FodelseAr, cluster(kommun)
			estimates store Gap
			coefplot (Gap, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
			graph export "$output\Fig3_`xvar'.png",  replace
			}		
		foreach xvar of varlist Totwage  {
			replace `xvar'=`xvar'/1000
			eststo: xi: reg `xvar' Y1997-Y2008 i.year i.Treat i.kommun i.FodelseAr, cluster(kommun)
			estimates store Gap
			coefplot (Gap, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-20(20)60)		
			graph export "$output\Fig3_`xvar'.png",  replace	
			}		
		}
	
	}



***************
* MAIN TABLES ***
***************

	***********
	* Table 1 *  
	***********
	{
			* Opening Data
			clear all	
			use "$path_base\RegSamp", clear
			foreach xvar of varlist DKtotwage Totwage SEKtotwage  {
			replace `xvar'=`xvar'/1000
			}
		
			* Generating additional outcomes
			destring Akassa, force replace
			gen work=(SEKwork==1 | DKwork==1)
			gen UI=(Akassa>0 & Akassa!=.)
			gen worknoUI=(work==1 & UI==0)
		
			* Running regressions
			foreach xvar of varlist DKwork SEKwork DKtotwage Totwage SEKtotwage work worknoUI UI {
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab1.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table1") ///
			
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab1.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table1") ///
			
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==1, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab1.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table1") 
			}
			
			
			* Examining if gender stratification results are significantly different from each other 
			
			
			* i. Opening Data
			clear all	
			use "$path_base\RegSamp", clear
			foreach xvar of varlist DKtotwage Totwage SEKtotwage  {
			replace `xvar'=`xvar'/1000
			}
			
			* ii. Constructing additional variables
			destring Akassa, force replace
			gen work=(SEKwork==1 | DKwork==1)
			gen UI=(Akassa>0 & Akassa!=.)
			gen worknoUI=(work==1 & UI==0)

			* iii. Generating gender-specific terms
			forvalues i=1997(1)2008 {
			gen MALEY`i'=Y`i' if Female==0
			replace MALEY`i'=0 if Female==1
			}
			
			destring FodelseAr, force replace
			gen MALEyear=year if Female==0
			gen MALEkommun=kommun if Female==0
			gen MALETreat=Treat if Female==0
			gen MALEFodelseAr=FodelseAr if Female==0
			
			replace MALEyear=0 if Female==1
			replace MALEkommun=0 if Female==1
			replace MALETreat=0 if Female==1
			replace MALEFodelseAr=0 if Female==1
			
			* iv. Running fully interacted model
			foreach xvar of varlist DKwork SEKwork DKtotwage Totwage SEKtotwage work worknoUI UI {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 MALEY1997-MALEY2008, a(Female year MALEyear kommun MALEkommun Treat MALETreat FodelseAr MALEFodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab1_GenderSpec.csv", replace keep(Y2008 MALEY2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table1") 
			}
			}		
			


	***********
	* Table 2 * 
	***********
	{
		* Opening data
		clear all
		use "$path_base\RegSamp", clear
		keep if Alder>24
		
		* Adjusting variable
		foreach xvar of varlist Totwage {
			replace `xvar'=`xvar'/1000
			}
			
		* Running regressions
		eststo clear
		foreach xvar of varlist DKwork Totwage {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0 & year<2009 & Educ==3, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table2") ///
			
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0 & year<2009 & (Educ==1  | Educ==2), a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table2") ///
			
			eststo: xi: reghdfe `xvar'  Y1997-Y2008 if Female==1 & year<2009 & Educ==3, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table2") ///
			
			eststo: xi: reghdfe `xvar'  Y1997-Y2008 if Female==1 & year<2009 & (Educ==1  | Educ==2), a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table2") 
			}
			
		* Examining if coefficients are significantly different
		
			* i. Opening data
			clear all
			use "$path_base\RegSamp", clear
			keep if Alder>24
		
			* ii. Adjusting variable 
			foreach xvar of varlist Totwage {
			replace `xvar'=`xvar'/1000
			}
			
			* iii. Generating interactions by education
			forvalues i=1997(1)2008 {
			gen EDY`i'=Y`i' if Educ==3
			replace EDY`i'=0 if Educ!=3
			}
			destring FodelseAr, force replace
			gen EDyear=year if Educ==3
			gen EDkommun=kommun if Educ==3
			gen EDTreat=Treat if Educ==3
			gen EDFodelseAr=FodelseAr if Educ==3
			
			replace EDyear=0 if Educ!=3
			replace EDkommun=0 if Educ!=3
			replace EDTreat=0 if Educ!=3
			replace EDFodelseAr=0 if Educ!=3
			
			* iv. Generating interactions by gender
			forvalues i=1997(1)2008 {
			gen MALEY`i'=Y`i' if Female==0
			replace MALEY`i'=0 if Female==1
			}
			
			gen MALEyear=year if Female==0
			gen MALEkommun=kommun if Female==0
			gen MALETreat=Treat if Female==0
			gen MALEFodelseAr=FodelseAr if Female==0
			
			replace MALEyear=0 if Female==1
			replace MALEkommun=0 if Female==1
			replace MALETreat=0 if Female==1
			replace MALEFodelseAr=0 if Female==1
			
			* v. Running regressions 	
			eststo clear
			foreach xvar of varlist DKwork Totwage {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 EDY1997-EDY2008 if Female==0, a(Educ kommun EDkommun Treat EDTreat year EDyear FodelseAr EDFodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2_EDGENDER_MALE.csv", replace keep(Y2008 EDY2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table2") ///
		
			eststo clear
			eststo: xi: reghdfe `xvar' Y1997-Y2008 EDY1997-EDY2008 if Female==1, a(Educ kommun EDkommun Treat EDTreat year EDyear FodelseAr EDFodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2_EDGENDER_FEMALE.csv", replace keep(Y2008 EDY2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table2") ///

			eststo clear
			eststo: xi: reghdfe `xvar' Y1997-Y2008 MALEY1997-MALEY2008 if Educ!=3, a(Female kommun MALEkommun Treat MALETreat year MALEyear FodelseAr MALEFodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2_EDGENDER_LOWED.csv", replace keep(Y2008 MALEY2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table2") ///

			eststo clear
			eststo: xi: reghdfe `xvar' Y1997-Y2008 MALEY1997-MALEY2008 if Educ==3, a(Female kommun MALEkommun Treat MALETreat year MALEyear FodelseAr MALEFodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2_EDGENDER_HIGHED.csv", replace keep(Y2008 MALEY2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Table2") ///
		}
		}	
		
			
				
	***********
	* Table 3 * 
	***********
	{

	* Cleaning and prep 
		use "$path_base\RegSamp", clear
		
		gen Kon=1 if Female==0
		replace Kon=2 if Female==1

		* i. Identifying couples
		bysort P0950_LopNr_FamId year: egen mar=sum(married)
		keep if mar==2 // keeping only families with two pepople that are married
		keep if married==1 // keeping the couple
		bysort P0950_LopNr_FamId year: egen coup=sum(Kon)
		keep if coup==3 // keeping only heterosexual couples as we are looking at the gender gap.

		* ii. Obtaining outcomes 
		foreach outc of varlist DKwork Totwage { 
		gen `outc'_Fem=`outc' if Female==1
		replace `outc'_Fem=0 if Female==0
		bysort P0950_LopNr_FamId year: egen F_`outc'=max(`outc'_Fem)
		replace `outc'=`outc'-F_`outc'
		}
		
		* iii. Only need one from each coulpes as outcomes are couple differences 
		keep if Female==0
		save "$path_base\Tab3", replace 


	* Running regressions and obtaining Baseline results	
		use "$path_base\Tab3", clear 

		eststo clear
		foreach xvar of varlist DKwork Totwage  {
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab3.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab3") ///
			
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if child==1, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab3.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab3") ///
			
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if child==0, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab3.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab3") 
			}	
		

	* Examining if the differences are significant across panels
			clear all
			use "$path_base\Tab3", clear 
			
				* i. Generating relevant interactions
				forvalues i=1997(1)2008 {
				gen MALEY`i'=Y`i' if child==1
				replace MALEY`i'=0 if child!=1
				}
				
				destring FodelseAr, force replace
				gen MALEyear=year if child==1
				gen MALEkommun=kommun if child==1
				gen MALETreat=Treat if child==1
				gen MALEFodelseAr=FodelseAr if child==1
				
				replace MALEyear=0 if child!=1
				replace MALEkommun=0 if child!=1
				replace MALETreat=0 if child!=1
				replace MALEFodelseAr=0 if child!=1
				
				gen C=(child==1)
			
				* ii. Running regressions
				eststo clear
				foreach xvar of varlist DKwork Totwage  {
				
				eststo: xi: reghdfe `xvar' Y1997-Y2008 MALEY1997-MALEY2008, a(C MALEkommun MALETreat MALEyear kommun Treat year FodelseAr MALEFodelseAr) tol(1e-6) cluster(kommun)
				estadd ysumm 
				esttab using "Tab3_WITHINHHGap.csv", replace keep(Y2008 MALEY2008) label nonumber ///
				stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab3") 
				}	
			}

			
	***********
	* Table 4 * 
	***********	
	{

	* Opening the data 
		use "$path_base\RegSamp", clear

	* Generating groups to estimate inequality from 	
		egen komyear=group(kommun year Female), label
		unique komyear
		
	* Calculating gini through user-program fastgini
		gen gini=. 
		forvalues i=1(1)1080 {
		qui fastgini Totwage if komyear==`i'
		qui replace gini=r(gini) if komyear==`i'
		}

	* Additional inequality measures
		gen IQR=.
		gen D9050=.
		gen D5010=.
		gen SD=.

		forvalues i=1(1)2256 {
		sum Totwage if komyear==`i', det 
		replace IQR=r(p75)-r(p25) if komyear==`i'
		replace D9050=r(p90)-r(p50) if komyear==`i'
		replace D5010=r(p50)-r(p10) if komyear==`i'
		replace SD=r(sd) if komyear==`i'
		}	
		
	* Saving for later (gini program takes a while)	
		save "$path_base\GINI", replace

	* Regressions
			foreach xvar of varlist D9050 D5010 IQR SD {
				replace `xvar'=`xvar'/1000
				
				eststo: xi: reg `xvar' Y1997-Y2008 i.year i.Treat i.kommun i.FodelseAr if Female==0, cluster(kommun)
				estadd ysumm 
				esttab using "Table4.csv", replace keep(Y2008) label nonumber ///
				stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab4") ///
				
				eststo: xi: reg `xvar'  Y1997-Y2008 i.year i.Treat i.kommun i.FodelseAr if Female==1, cluster(kommun)
				estadd ysumm 
				esttab using "Table4.csv", replace keep(Y2008) label nonumber ///
				stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab4") 
				}	
				
				foreach xvar of varlist gini {
				eststo: xi: reg `xvar' Y1997-Y2008 i.year i.Treat i.kommun i.FodelseAr if Female==0, cluster(kommun)
				estadd ysumm 
				esttab using "Table4.csv", replace keep(Y2008) label nonumber ///
				stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab4") //
				
				eststo: xi: reg `xvar'  Y1997-Y2008 i.year i.Treat i.kommun i.FodelseAr if Female==1, cluster(kommun)
				estadd ysumm 
				esttab using "Table4.csv", replace keep(Y2008) label nonumber ///
				stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab4") 
				}	

	* Examining if they are significantly different
			* i. Opening data
			use "$path_base\GINI", clear 
		
			* ii. Generating interactions 
			forvalues i=1997(1)2008 {
			gen MALEY`i'=Y`i' if Female==0
			replace MALEY`i'=0 if Female==1
			}
		
			destring FodelseAr, force replace
			gen MALEyear=year if Female==0
			gen MALEkommun=kommun if Female==0
			gen MALETreat=Treat if Female==0
			gen MALEFodelseAr=FodelseAr if Female==0
			
			replace MALEyear=0 if Female==1
			replace MALEkommun=0 if Female==1
			replace MALETreat=0 if Female==1
			replace MALEFodelseAr=0 if Female==1
			
			* iii. Estimating regressions 
			eststo clear
			foreach xvar of varlist D9050 D5010 IQR SD {
				replace `xvar'=`xvar'/1000
				
				eststo: xi: reghdfe `xvar' Y1997-Y2008 MALEY1997-MALEY2008 if year<2009, tol(1e-6) a(MALEyear year MALETreat Treat MALEkommun kommun Female FodelseAr MALEFodelseAr) cluster(kommun)
				estadd ysumm 
				esttab using "Table4_WITHINGENDERINEQ.csv", replace keep(Y2008 MALEY2008) label nonumber ///
				stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab4") 
				}	
				
				foreach xvar of varlist gini {
				eststo: xi: reghdfe `xvar' Y1997-Y2008 MALEY1997-MALEY2008 if year<2009, tol(1e-6) a(MALEyear year MALETreat Treat MALEkommun kommun Female FodelseAr MALEFodelseAr) cluster(kommun)
				estadd ysumm 
				esttab using "Table4_WITHINGENDERGINI.csv", replace keep(Y2008 MALEY2008) label nonumber ///
				stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Tab4") //
				}	
	}


	
	
**************
**************
** APPENDIX **
**************
**************
		
*************
** FIGURES **
*************

	*************
	* Figure B1 *
	*************
	* Not produced in Stata

	*************
	* Figure B2 *
	*************	
	* Not produced in Stata
		
	*************
	* Figure B3 *
	*************	
	* Not produced in Stata	
			
	*************
	* Figure B4 *
	*************	
	* Not produced in Stata	

	*************
	* Figure B5 *
	*************	
	* Not produced in Stata	

	*************
	* Figure B6 *
	*************	
	* Not produced in Stata	

	*************
	* Figure B7 *
	*************
	{
	* Opening data 
		use "$path_base\RegSamp3", clear
		
	* Imposing restrictions 
		keep P0950_LopNr_PersonNr year kommun Alder Lan								// keeping relevant variables
		destring Lan, force replace
		reshape wide kommun Alder Lan, i(P0950_LopNr_PersonNr) j(year) 					// Reshapong to long format
		
		forvalues i=1998(1)2008 {												// initiating year loop 
				local j=`i'-1
				local l=`i'+1
		
				gen Inmig_`i'  = (kommun`j'!= kommun`i' & Alder`i'>18)				// Making a person-year an inmigrant if lived in a different city last year (conditional on 18 plus, because sample restricted to 18 or older, so dont know where they lived when they were 18 or less, so cant assign value)
				gen Outmig_`i' = (kommun`i'!= kommun`l' & Alder`i'<64)				// Making a person-year an outmigrant if lived in a different city next year compared to this year when lived in one of our analysis cities (conditional on less than 64 this year, because sample restricted to 64 or less, so dont know where they lived if 64 or more, so cant assign value) 
				gen Kfrom_`i'  = kommun`j' if Inmig_`i'  == 1
				gen Kto_`i'    = kommun`l' if Outmig_`i' == 1
				}
				
			reshape long Alder kommun Lan Inmig_ Outmig_ Kfrom_ Kto_, i(P0950_LopNr_PersonNr) j(year)
			drop if year==1997
			drop if year==2009
			
			ren Inmig_ inmigration
			ren Outmig_ outmigration
			ren Kto_ Kto
			ren Kfrom_ Kfrom

			gen FSkane	= .
			gen FControl= .
			gen FBig10	= .
			gen Fother	= .
			gen LanF=int(Kfrom/100)
			ren Kfrom kommunF

			gen TSkane	= .
			gen TControl= .
			gen TBig10	= .
			gen Tother	= .
			gen LanT=int(Kto/100)
			ren Kto kommunT

			keep if kommun==1280 
			gen observations=1
			
			replace FSkane		= 1 if LanF == 12
			replace FControl 	= 1 if LanF==7 | LanF==10 | LanF==13 | LanF==6 | LanF==8
			replace FBig10 		= 1 if kommunF==180 | kommunF==1480 | kommunF==380 | kommunF==580 | kommunF==1980 | kommunF==1880 | kommunF==581 | kommunF==680 | kommunF==2480 | kommunF==1490
			replace Fother 		= 1 if FSkane == . & FControl == . & FControl == . & FBig10 == . & inmigration==1

			replace TSkane		= 1 if LanT == 12
			replace TControl 	= 1 if LanT == 7 | LanT==10 | LanT==13  | LanT==6 | LanT==8
			replace TBig10 		= 1 if kommunT==180 | kommunT==1480 | kommunT==380 | kommunT==580 | kommunT==1980 | kommunT==1880 | kommunT==581 | kommunT==680 | kommunT==2480 | kommunT==1490
			replace Tother 		= 1 if TSkane == . & TControl == . & TControl == . & TBig10 == . & outmigration==1
								
			graph bar (sum) FSkane FControl FBig10 Fother if inmigration==1, over(year) stack legend(order(1 "Skane" 2 "No-Skane Border Muns." 3 "No-Skane No-Border Big Cs." 4 "Other")) 
			graph export "$output\FigureA7_Inmigration.png",  replace
			graph bar (sum) TSkane TControl TBig10 Tother if outmigration==1, over(year) stack legend(order(1 "Skane" 2 "No-Skane Border Muns." 3 "No-Skane No-Border Big Cs." 4 "Other"))  
			graph export "$output\FigureA7_Outmigration.png",  replace
	}

	*************
	* Figure B8 *
	*************	
	* Not produced in Stata	

	*************
	* Figure B9 *
	*************	
	{
		* Opening data and imposing restrictions
		use 				"`path_base'\RegSamp", clear
		destring AstKom_Arb, force replace
		keep if kommun		== 1280
		keep if year 		== 1999 | year 	== 2008
		gen obs=1
		
		collapse (sum) obs, by(year AstKom_Arb AstKom_Namn_Arb)
		
		* Fixing format of outcome variables 
		sort 				AstKom_Arb year
		gen 				obs_1999	=  obs if year==1999
		gen 				obs_2008	=  obs if year==2008
		
		replace obs_1999=0 if obs_1999==.
		replace obs_2008=0 if obs_2008==.

		* Collapsing to munic level and sorting
		collapse (sum) obs_1999 obs_2008, by(AstKom_Arb AstKom_Namn_Arb)
		sort 				AstKom_Arb
		
		* NOTE: At this point, i've manually added together the places with same code but different names before proceeding to next line (issue due to special characters)
		* Replication of figure will require that interested researcher does the same.
		drop if obs_2008<11
		save 				"`path_base'\Ghold.dta", replace

		* Outputting graphs
		graph bar obs_1999 obs_2004 obs_2008, over(AstKom_Namn_Arb, sort(obs_2008)) legend(label(1 "Workers 99") label(2 "Workers 08"))
		graph export "$output\FigureA8.png", as(png) replace
		
	}


	**************
	* Figure B10 *
	**************	
	{
		use "$path_base\RegSamp3", clear
		drop Treat Y1997-Y2008
		keep if Lan==12 | Lan==7 | Lan==10 | Lan==13 | Lan==6 | Lan==8
		gen Treat=(Lan==12)
		gen Y1997 = (year==1997 & Treat==1)
		gen Y1998 = (year==1998 & Treat==1)
		gen Y1999 = 0
		gen Y2000 = (year==2000 & Treat==1)
		gen Y2001 = (year==2001 & Treat==1)
		gen Y2002 = (year==2002 & Treat==1)
		gen Y2003 = (year==2003 & Treat==1)
		gen Y2004 = (year==2004 & Treat==1)
		gen Y2005 = (year==2005 & Treat==1)
		gen Y2006 = (year==2006 & Treat==1)
		gen Y2007 = (year==2007 & Treat==1)
		gen Y2008 = (year==2008 & Treat==1)

		eststo clear
		forvalues i=1214/1299 {
		count if kommun==`i'		// some of the numbers above are not real municipality numbers; next line fixes that. 
		if r(N)>0 {
			eststo: xi: reghdfe DKwork Y1997-Y2008 if (kommun==`i' | Lan!=12), a(year Treat kommun FodelseAr) cluster(kommun)
			estadd ysumm
			estadd local Mun "`i'"
			esttab using "Fig2.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N Mun) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) title("Scania spillovers") ///
			}
			}
			}


	**************
	* Figure B11 *
	**************		
	{
		use "$path_base\RegSamp3", clear
		destring AstKom_Arb, force replace
		keep if AstKom_Arb	!= .
		keep if Lan 		== "12"
		keep if year 		== 1999 | year 	== 2008
		
		collapse (sum) obs, by(year AstKom_Arb AstKom_Namn_Arb)
		
		* Fixing format of outcome variables 
		sort 				AstKom_Arb year
		gen 				obs_1999	=  obs if year==1999
		gen 				obs_2008	=  obs if year==2008
		
		replace obs_1999=0 if obs_1999==.
		replace obs_2008=0 if obs_2008==.

		* Collapsing to munic level and sorting
		collapse (sum) obs_1999 obs_2008, by(AstKom_Arb AstKom_Namn_Arb)
		sort 				AstKom_Arb
		
		* NOTE: At this point, i've manually added together the places with same code but different names before proceeding to next line (issue due to special characters)
		* Replication of figure will require that you do the same
		drop if obs_2008<21
		save 				"`path_base'\Ghold2.dta", replace

		* Outputting graphs
		graph bar obs_1999 obs_2008, over(AstKom_Namn_Arb, sort(obs_2008)) legend(label(1 "Workers 99") label(2 "Workers 08"))
		graph export "$output\FigureA11.png", as(png) replace
	}


	**************
	* Figure B12 *
	**************	
	{
		eststo clear
		use "$path_base\RegSamp", clear	
		append using "$path_base\Individ1995_1996", force

			
			foreach xvar of varlist SEKwork {
				eststo: xi: reghdfe `xvar' Y1995-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store General
				coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1995" 2 "1996" 3 "1997" 4 "1998" 5 "1999" 6 "2000" ///
				7 "2001" 8 "2002" 9 "2003" 10 "2004" 11 "2005" 12 "2006" 13 "2007" 14 "2008", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
				graph export "$output\FigA12_`xvar'.png",  replace
				}	
				
			foreach xvar of varlist SEKtotwage  {
				replace `xvar'=`xvar'/1000
				eststo: xi: reghdfe `xvar' Y1995-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store General
				coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1995" 2 "1996" 3 "1997" 4 "1998" 5 "1999" 6 "2000" ///
				7 "2001" 8 "2002" 9 "2003" 10 "2004" 11 "2005" 12 "2006" 13 "2007" 14 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
				(horizontal) nogrid) ylabel(-20(20)60)		
				graph export "$output\FigA12_`xvar'.png",  replace
				}	
	}


	**************
	* Figure B13 *
	**************
	* Not produced on server


	**************
	* Figure B14 *
	**************
	{
	* Panels A and B
	{
	clear all	
			use "$path_base\RegSamp", clear
			foreach xvar of varlist DKtotwage Totwage  {
			replace `xvar'=`xvar'/1000
			}

		foreach xvar of varlist Totwage  {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Male
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==1, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Female
			coefplot (Male, mcolor(gs10) ciopts(lcolor(gs10))) (Female, mcolor(gs0) ciopts(lcolor(gs0))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-20(20)60)		
				graph export "$output\FigA13a_`xvar'.png",  replace
	}
		foreach xvar of varlist DKwork  {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Male
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==1, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Female
			coefplot (Male, mcolor(gs10) ciopts(lcolor(gs10))) (Female, mcolor(gs0) ciopts(lcolor(gs0))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
				graph export "$output\FigA13a_`xvar'.png",  replace
	}
	}

	* Panels B and C
	{
		clear all
		use "$path_base\RegSamp", clear
		keep if Alder>24		// Restriction for age to allow majority to graduate. Same as in main paper. 

		foreach xvar of varlist Totwage {
			replace `xvar'=`xvar'/1000
			}
			
		eststo clear
		foreach xvar of varlist DKwork {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0 & year<2009 & Educ==3, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Male_HighEd
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0 & year<2009 & (Educ==1  | Educ==2), a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Male_LowEd
			eststo: xi: reghdfe `xvar'  Y1997-Y2008 if Female==1 & year<2009 & Educ==3, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Female_HighEd
			eststo: xi: reghdfe `xvar'  Y1997-Y2008 if Female==1 & year<2009 & (Educ==1  | Educ==2), a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Female_LowEd
				
				coefplot (Male_HighEd, mcolor(blue) ciopts(lcolor(blue))) (Male_LowEd, mcolor(green) ciopts(lcolor(green))) ///
				(Female_LowEd, mcolor(purple) ciopts(lcolor(purple))) (Female_HighEd, mcolor(sand) ciopts(lcolor(sand))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
				graph export "$output\FigA13b_`xvar'.png",  replace
			}
			
		eststo clear
		foreach xvar of varlist Totwage {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0 & year<2009 & Educ==3, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Male_HighEd
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0 & year<2009 & (Educ==1  | Educ==2), a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Male_LowEd
			eststo: xi: reghdfe `xvar'  Y1997-Y2008 if Female==1 & year<2009 & Educ==3, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Female_HighEd
			eststo: xi: reghdfe `xvar'  Y1997-Y2008 if Female==1 & year<2009 & (Educ==1  | Educ==2), a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estimates store Female_LowEd
				
				coefplot (Male_HighEd, mcolor(blue) ciopts(lcolor(blue))) (Male_LowEd, mcolor(green) ciopts(lcolor(green))) ///
				(Female_LowEd, mcolor(purple) ciopts(lcolor(purple))) (Female_HighEd, mcolor(sand) ciopts(lcolor(sand))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-20(20)60)		
				graph export "$output\FigA13b_`xvar'.png",  replace
			}
			
	}

	}


	**************
	* Figure B15 *
	**************
	* Not produced on server


	**************
	* Figure B16 *
	**************
	{
	* TOP 30  cities (>50,000) excluding Stockholm local labor market (LA1701 according to SCB 2017)
				* Concerns following municipalities: kommun==180  | kommun==126 | kommun==182 | kommun==181 | kommun==127 | kommun==136 | kommun==184 | kommun==123 | kommun==163 | kommun==160 | kommun==188 | kommun==183 | kommun==380 
				
		* Opening the data 
		use "$path_base\RegSamp3", clear
		eststo clear

		* Restricting to relevant munics 
		keep if kommun==1280 | kommun==1480 | kommun==580 | kommun==1880 | kommun==1980 | kommun==581 | kommun==680 | kommun==2480 | kommun==1490 ///
							 | kommun==484 | kommun== 1380 | kommun==2180 | kommun==2281 | kommun==780 | kommun==1780 | kommun==1384 |  kommun==2580 /// 
							 | kommun==2482 | kommun==880 | kommun==1481 | kommun==1080 | kommun==1383 | kommun==2380 | kommun==980 | kommun==2080 ///
							 | kommun==1488 | kommun==1485 | kommun==480 | kommun==2284 | kommun==1496 | kommun==2081 
							 
		* Performing estimation 					 
		foreach xvar of varlist DKwork  {
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr, a(kommun) cluster(kommun)
			estimates store General
			coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
			graph export "$output\FigureA16_Top30_`xvar'.png",  replace
			}	
		foreach xvar of varlist Totwage  {
			replace `xvar'=`xvar'/1000
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr, a(kommun) cluster(kommun)
			estimates store General
			coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-20(20)60)		
			graph export "$output\FigureA16_Top30_`xvar'.png",  replace
			}
		
	* SYNTHETIC CONTROL 	
		use "$path_base\RegSamp3", clear
		
		gen child=(Nrchildren>0 & Nrchildren!=.)
		collapse (sum) population (mean) DKwork SEKwork DKtotwage Totwage SEKtotwage Treat age immigrant married baplus empl female child, by(kommun year)
		sum population, detail
		drop if population<r(p5)	// avoiding minor villages
		bysort kommun: gen ps=_N
		keep if ps==13 				// Ensuring balanced panel (requirement for the synth command)
		tsset kommun year	
		foreach xvar of varlist Totwage DKwork {
			preserve
			synth `xvar' population age married immigrant baplus child empl, trperiod(2000) trunit(1280) figure
			matrix Q=e(Y_treated)
			matrix P=e(Y_synthetic) 
			matrix TE=Q-P
			svmat TE, name(difference)
			save "$output\FigureA16_SynthCont_`xvar'.dta", replace
			restore
			}
	}


	**************
	* Figure B17 *
	**************
	{
	* TOP 30  cities 
		* Opening the data 
		use "$path_base\RegSamp3", clear
		eststo clear

		* Restricting to relevant munics 
		keep if kommun==1280 | kommun==1480 | kommun==580 | kommun==1880 | kommun==1980 | kommun==581 | kommun==680 | kommun==2480 | kommun==1490 ///
							 | kommun==484 | kommun== 1380 | kommun==2180 | kommun==2281 | kommun==780 | kommun==1780 | kommun==1384 |  kommun==2580 /// 
							 | kommun==2482 | kommun==880 | kommun==1481 | kommun==1080 | kommun==1383 | kommun==2380 | kommun==980 | kommun==2080 ///
							 | kommun==1488 | kommun==1485 | kommun==480 | kommun==2284 | kommun==1496 | kommun==2081 
							 
		* Performing estimation 					 
		foreach xvar of varlist DKwork  {
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if Female==1, a(kommun) cluster(kommun)
			estimates store General
			coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
			graph export "$output\FigureA17_Top30_`xvar'_F.png",  replace
			}	
		foreach xvar of varlist Totwage  {
			replace `xvar'=`xvar'/1000
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if Female==1, a(kommun) cluster(kommun)
			estimates store General
			coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-20(20)60)		
			graph export "$output\FigureA17_Top30_`xvar'_F.png",  replace
			}
		
	* SYNTHETIC CONTROL 	
		use "$path_base\RegSamp3", clear
		
		keep if female==1
		
		gen child=(Nrchildren>0 & Nrchildren!=.)
		collapse (sum) population (mean) DKwork SEKwork DKtotwage Totwage SEKtotwage Treat age immigrant married baplus empl female child, by(kommun year)
		sum population, detail
		drop if population<r(p5)	// avoiding minor villages
		bysort kommun: gen ps=_N
		keep if ps==13 				// Ensuring balanced panel 
		tsset kommun year	
		foreach xvar of varlist Totwage DKwork {
			preserve
			synth `xvar' population age married immigrant baplus child empl, trperiod(2000) trunit(1280) figure
			matrix Q=e(Y_treated)
			matrix P=e(Y_synthetic) 
			matrix TE=Q-P
			svmat TE, name(difference)
			save "$output\FigureA17_SynthCont_`xvar'_F.dta", replace
			restore
			}
	}


	**************
	* Figure B18 *
	**************
	{
	* TOP 30  cities 
		* Opening the data 
		use "$path_base\RegSamp3", clear
		eststo clear

		* Restricting to relevant munics 
		keep if kommun==1280 | kommun==1480 | kommun==580 | kommun==1880 | kommun==1980 | kommun==581 | kommun==680 | kommun==2480 | kommun==1490 ///
							 | kommun==484 | kommun== 1380 | kommun==2180 | kommun==2281 | kommun==780 | kommun==1780 | kommun==1384 |  kommun==2580 /// 
							 | kommun==2482 | kommun==880 | kommun==1481 | kommun==1080 | kommun==1383 | kommun==2380 | kommun==980 | kommun==2080 ///
							 | kommun==1488 | kommun==1485 | kommun==480 | kommun==2284 | kommun==1496 | kommun==2081 
							 
		* Performing estimation 					 
		foreach xvar of varlist DKwork  {
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if Female==0, a(kommun) cluster(kommun)
			estimates store General
			coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
			graph export "$output\FigureA18_Top30_`xvar'_F.png",  replace
			}	
		foreach xvar of varlist Totwage  {
			replace `xvar'=`xvar'/1000
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if Female==0, a(kommun) cluster(kommun)
			estimates store General
			coefplot (General, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-20(20)60)		
			graph export "$output\FigureA18_Top30_`xvar'_F.png",  replace
			}
		
	* SYNTHETIC CONTROL 	
		use "$path_base\RegSamp3", clear
		
		keep if female==0
		
		gen child=(Nrchildren>0 & Nrchildren!=.)
		collapse (sum) population (mean) DKwork SEKwork DKtotwage Totwage SEKtotwage Treat age immigrant married baplus empl female child, by(kommun year)
		sum population, detail
		drop if population<r(p5)	// avoiding minor villages
		bysort kommun: gen ps=_N
		keep if ps==13 				// Ensuring balanced panel 
		tsset kommun year	
		foreach xvar of varlist Totwage DKwork {
			preserve
			synth `xvar' population age married immigrant baplus child empl, trperiod(2000) trunit(1280) figure
			matrix Q=e(Y_treated)
			matrix P=e(Y_synthetic) 
			matrix TE=Q-P
			svmat TE, name(difference)
			save "$output\FigureA18_SynthCont_`xvar'_F.dta", replace
			restore
			}
	}


	* Synth Figures for Figures B16 through B18:
	{
	*** FOLLOWING CODE MAKES ALL THE SYNTHETHIC FIGURES FROM THE DTA FILES CREATED ABOVE for A15, A16, and A17. ***

	use "$output\FigureA16_SynthCont_DKwork.dta", clear
	keep year difference1
	gen D=difference1 if year==1999
	egen Norm=max(D)
	drop if difference1==.
	gen Effect=difference1-Norm
	keep year Effect
	drop if year==2009
	twoway (scatter Effect year), yline(0, lpattern(dot) lcolor(black)) xline(2000, lpattern(dash) lcolor(black)) xlabel(1997(1)2008, angle(45)) graphregion(color(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08) ytitle("") xtitle("")
	graph export "$output\FigA16_SYNTH_DKWORK.png",  replace


	use "$output\FigureA16_SynthCont_Totwage.dta", clear
	keep year difference1
	gen D=difference1 if year==1999
	egen Norm=max(D)
	drop if difference1==.
	gen Effect=difference1-Norm
	keep year Effect
	drop if year==2009
	replace Effect=Effect/1000
	twoway (scatter Effect year), yline(0, lpattern(dot) lcolor(black)) xline(2000, lpattern(dash) lcolor(black)) xlabel(1997(1)2008, angle(45)) graphregion(color(white)) ylabel(, angle (horizontal) nogrid) ylabel(-20(20)60) ytitle("") xtitle("")
	graph export "$output\FigA16_SYNTH_TOTWAGE.png",  replace

	use "$output\FigureA17_SynthCont_DKwork.dta", clear
	keep year difference1
	gen D=difference1 if year==1999
	egen Norm=max(D)
	drop if difference1==.
	gen Effect=difference1-Norm
	keep year Effect
	drop if year==2009
	twoway (scatter Effect year), yline(0, lpattern(dot) lcolor(black)) xline(2000, lpattern(dash) lcolor(black)) xlabel(1997(1)2008, angle(45)) graphregion(color(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08) ytitle("") xtitle("")
	graph export "$output\FigA17_SYNTH_DKWORK.png",  replace


	use "$output\FigureA17_SynthCont_Totwage.dta", clear
	keep year difference1
	gen D=difference1 if year==1999
	egen Norm=max(D)
	drop if difference1==.
	gen Effect=difference1-Norm
	keep year Effect
	drop if year==2009
	replace Effect=Effect/1000
	twoway (scatter Effect year), yline(0, lpattern(dot) lcolor(black)) xline(2000, lpattern(dash) lcolor(black)) xlabel(1997(1)2008, angle(45)) graphregion(color(white)) ylabel(, angle (horizontal) nogrid) ylabel(-20(20)60) ytitle("") xtitle("")
	graph export "$output\FigA17_SYNTH_TOTWAGE.png",  replace

	use "$output\FigureA18_SynthCont_DKwork.dta", clear
	keep year difference1
	gen D=difference1 if year==1999
	egen Norm=max(D)
	drop if difference1==.
	gen Effect=difference1-Norm
	keep year Effect
	drop if year==2009
	twoway (scatter Effect year), yline(0, lpattern(dot) lcolor(black)) xline(2000, lpattern(dash) lcolor(black)) xlabel(1997(1)2008, angle(45)) graphregion(color(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08) ytitle("") xtitle("")
	graph export "$output\FigA18_SYNTH_DKWORK.png",  replace


	use "$output\FigureA18_SynthCont_Totwage.dta", clear
	keep year difference1
	gen D=difference1 if year==1999
	egen Norm=max(D)
	drop if difference1==.
	gen Effect=difference1-Norm
	keep year Effect
	drop if year==2009
	replace Effect=Effect/1000
	twoway (scatter Effect year), yline(0, lpattern(dot) lcolor(black)) xline(2000, lpattern(dash) lcolor(black)) xlabel(1997(1)2008, angle(45)) graphregion(color(white)) ylabel(, angle (horizontal) nogrid) ylabel(-20(20)60) ytitle("") xtitle("")
	graph export "$output\FigA18_SYNTH_TOTWAGE.png",  replace
	}


	**************
	* Figure B19 *
	**************
	{
	* Panels A and B
		use "$path_base\RegSamp3", clear

		* Treatment indicator 
		drop Y1997 Y1998 Y1999 Y2000 Y2001 Y2002 Y2003 Y2004 Y2005 Y2006 Y2007 Y2008 Treat
		gen Treat=(kommun==1283 | kommun==1280)
			
		* Sample restrictions
		keep if kommun==1283 | kommun==1280 | Lan==7 | Lan==10 | Lan==13 | Lan==6 | Lan==8
		
		* Default categories in regression
		char year[omit] 1999
		
		* Relative-time x Treatment indicators
		gen Y1997 = (year==1997 & Treat==1)
		gen Y1998 = (year==1998 & Treat==1)
		gen Y1999 = 0
		gen Y2000 = (year==2000 & Treat==1)
		gen Y2001 = (year==2001 & Treat==1)
		gen Y2002 = (year==2002 & Treat==1)
		gen Y2003 = (year==2003 & Treat==1)
		gen Y2004 = (year==2004 & Treat==1)
		gen Y2005 = (year==2005 & Treat==1)
		gen Y2006 = (year==2006 & Treat==1)
		gen Y2007 = (year==2007 & Treat==1)
		gen Y2008 = (year==2008 & Treat==1)

		* Estimation 
		eststo clear
		foreach xvar of varlist DKwork {
			char kommun[omit] 1280
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1283, a(kommun) cluster(kommun)
			estimates store Malm
			char kommun[omit] 1283
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1280, a(kommun) cluster(kommun)
			estimates store Hels
			coefplot (Malm, mcolor(black) ciopts(lcolor(black))) (Hels, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-0.02(0.02)0.08)			
			graph export "$output\FigureA19A_`xvar'.png",  replace
			}	
			
			foreach xvar of varlist Totwage {
			replace `xvar'=`xvar'/1000
			char kommun[omit]  1280
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1283, a(kommun) cluster(kommun)
			estimates store Malm
			char kommun[omit] 1283 
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1280, a(kommun) cluster(kommun)
			estimates store Hels
			coefplot (Malm, mcolor(black) ciopts(lcolor(black))) (Hels, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-20(20)60)			
			graph export "$output\FigureA19B_`xvar'.png",  replace
			}	

		
	* Panels C through F
		use "$path_base\RegSamp3", clear

		* Treatment indicator 
		drop Y1997 Y1998 Y1999 Y2000 Y2001 Y2002 Y2003 Y2004 Y2005 Y2006 Y2007 Y2008 Treat
		gen Treat=(kommun==1283 | kommun==1280)
			
		* Sample restrictions
		keep if kommun==1283 | kommun==1280 | Lan==7 | Lan==10 | Lan==13  | Lan==6 | Lan==8
		
		* Default categories in regression
		char year[omit] 1999
		
		* Relative-time x Treatment indicators
		gen Y1997 = (year==1997 & Treat==1)
		gen Y1998 = (year==1998 & Treat==1)
		gen Y1999 = 0
		gen Y2000 = (year==2000 & Treat==1)
		gen Y2001 = (year==2001 & Treat==1)
		gen Y2002 = (year==2002 & Treat==1)
		gen Y2003 = (year==2003 & Treat==1)
		gen Y2004 = (year==2004 & Treat==1)
		gen Y2005 = (year==2005 & Treat==1)
		gen Y2006 = (year==2006 & Treat==1)
		gen Y2007 = (year==2007 & Treat==1)
		gen Y2008 = (year==2008 & Treat==1)

		* Estimation 
		preserve 
		keep if Female==1
		eststo clear
		foreach xvar of varlist DKwork {
			char kommun[omit] 1280
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1283, a(kommun) cluster(kommun)
			estimates store Malm
			char kommun[omit] 1283
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1280, a(kommun) cluster(kommun)
			estimates store Hels
			coefplot (Malm, mcolor(black) ciopts(lcolor(black))) (Hels, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-0.02(0.02)0.08)			
			graph export "$output\FigureA19E_`xvar'.png",  replace
			}	
			
			foreach xvar of varlist Totwage {
			replace `xvar'=`xvar'/1000
			char kommun[omit]  1280
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1283, a(kommun) cluster(kommun)
			estimates store Malm
			char kommun[omit] 1283 
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1280, a(kommun) cluster(kommun)
			estimates store Hels
			coefplot (Malm, mcolor(black) ciopts(lcolor(black))) (Hels, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-20(20)60)			
			graph export "$output\FigureA19F_`xvar'.png",  replace
			}
		restore
		
		preserve 
		keep if Female==0
		eststo clear
		foreach xvar of varlist DKwork {
			char kommun[omit] 1280
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1283, a(kommun) cluster(kommun)
			estimates store Malm
			char kommun[omit] 1283
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1280, a(kommun) cluster(kommun)
			estimates store Hels
			coefplot (Malm, mcolor(black) ciopts(lcolor(black))) (Hels, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-0.02(0.02)0.08)			
			graph export "$output\FigureA19C_`xvar'.png",  replace
			}	
			
			foreach xvar of varlist Totwage {
			replace `xvar'=`xvar'/1000
			char kommun[omit]  1280
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1283, a(kommun) cluster(kommun)
			estimates store Malm
			char kommun[omit] 1283 
			eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if kommun!=1280, a(kommun) cluster(kommun)
			estimates store Hels
			coefplot (Malm, mcolor(black) ciopts(lcolor(black))) (Hels, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
			7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008", angle(45)) graphregion(color(white)) ylabel(, angle ///
			(horizontal) nogrid) ylabel(-20(20)60)			
			graph export "$output\FigureA19D_`xvar'.png",  replace
			}	
		restore
	}	
		

	**************
	* Figure B20 *
	**************
	* Not produced on server


	**************
	* Figure B21 *
	**************
	{
	* Panels A and B 
		eststo clear
		use "$path_base\RegSamp1", clear
		
			foreach xvar of varlist DKwork {
				eststo: xi: reghdfe `xvar' Y1997-Y2014 if Female==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Male
				eststo: xi: reghdfe `xvar' Y1997-Y2014 if Female==1, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Female
				coefplot (Male, mcolor(black) ciopts(lcolor(black))) (Female, mcolor(gs7) ciopts(lcolor(gs7))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008" 13 "2009" 14 "2010" 15 "2011" ///
				 16 "2012" 17 "2013" 18 "2014", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08)		
				graph export "$output\FigA21a_`xvar'.png",  replace	
				}	
			foreach xvar of varlist Totwage  {
				replace `xvar'=`xvar'/1000
				eststo: xi: reghdfe `xvar' Y1997-Y2014 if Female==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Male
				eststo: xi: reghdfe `xvar' Y1997-Y2014 if Female==1, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
				estimates store Female
				coefplot (Male, mcolor(black) ciopts(lcolor(black))) (Female, mcolor(gs7) ciopts(lcolor(gs7))), keep(Y*) ///
				level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
				omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008" 13 "2009" 14 "2010" 15 "2011" ///
				 16 "2012" 17 "2013" 18 "2014", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-20(20)60)	
				graph export "$output\FigA21b_`xvar'.png",  replace
				}	
				
	* Panels C and D		
		use "$path_base\RegSamp1", clear
			compress
			drop if year>2014

		gen Kon=1 if Female==0
		replace Kon=2 if Female==1
		
		* i. Identifying couples
		bysort P0950_LopNr_FamId year: egen mar=sum(married)
		keep if mar==2 // keeping only families with two pepople that are married
		keep if married==1 // keeping the ones that are married 
		bysort P0950_LopNr_FamId year: egen coup=sum(Kon)
		keep if coup==3 // keeping only heterosexual couples since we are interested in the gender gap.
			
		* ii. Obtaining outcomes 
		foreach outc of varlist DKwork SEKwork DKtotwage Totwage SEKtotwage { 
		gen `outc'_Fem=`outc' if Female==1
		replace `outc'_Fem=0 if Female==0
		bysort P0950_LopNr_FamId year: egen F_`outc'=max(`outc'_Fem)
		replace `outc'=`outc'-F_`outc'
		}
		
		* iii. Only need one from each coulpes as outcomes are couple differences 
		keep if Female==0
		
		* iv. Running the regressions
		eststo clear
		foreach xvar of varlist DKwork {
			eststo: xi: reg `xvar' Y1997-Y2014 i.year i.Treat i.kommun i.FodelseAr, cluster(kommun)
			estimates store Gap
			coefplot (Gap, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008" 13 "2009" 14 "2010" 15 "2011" ///
				 16 "2012" 17 "2013" 18 "2014", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-0.02(0.02)0.08)			
			graph export "$output\FigA21c_`xvar'.png",  replace
			}		
		foreach xvar of varlist Totwage  {
			replace `xvar'=`xvar'/1000
			eststo: xi: reg `xvar' Y1997-Y2014 i.year i.Treat i.kommun i.FodelseAr, cluster(kommun)
			estimates store Gap
			coefplot (Gap, mcolor(gs10) ciopts(lcolor(gs10))), keep(Y*) ///
			level(95) yline(0, lpattern(dot) lcolor(black)) xline(4, lpattern(dash) lcolor(black)) ///
			omitted baselevels vertical xlabel(1 "1997" 2 "1998" 3 "1999" 4 "2000" 5 "2001" 6 "2002" ///
				7 "2003" 8 "2004" 9 "2005" 10 "2006" 11 "2007" 12 "2008" 13 "2009" 14 "2010" 15 "2011" ///
				 16 "2012" 17 "2013" 18 "2014", angle(45)) graphregion(color ///
				(white)) ylabel(, angle (horizontal) nogrid) ylabel(-20(20)60)
			graph export "$output\FigA21d_`xvar'.png",  replace	
			}		
		}


*************
** TABLES **
*************

	************
	* Table B1 *	
	************
	{
	* Opening the data 
	use "$path_base\RegSamp", clear

	* Counting job stint in Denmark
	bysort P0950_LopNr_PersonNr: egen DKK=sum(DKwork)
		duplicates drop P0950_LopNr_PersonNr, force
		tab DKK if Lan==12 & DKK!=0
		sum DKK if Lan==12 & DKK!=0
		drop if Lan==12  & kommun!=1280
		tab DKK if Lan==12 & DKK!=0
		sum DKK if Lan==12 & DKK!=0
	}

	************
	* Table B2 *	
	************
	{
	* Opening the data 
	use "$path_base\RegSamp3", clear
	keep if year==1999

	* Generating variables 
	gen mths=(Educ==3)
	gen employed=(LoneInk!=0 & 0<LoneInk)
	replace LoneInk=LoneInk/100
	gen Children=Barn0_3+ Barn4_6+ Barn7_10+ Barn11_15+ Barn16_17
	gen invand=(SenInvAr!=0 & SenInvAr!=.)

	* Obtaining descriptives
	outreg2 using "TableA2Malmo.doc" if kommun==1280, replace sum(log) keep( Alder Female AntFlyttTot AntFlyttKommun LoneInk mths employed Akassa Children invand married)
	outreg2 using "TableA2BaseControl.doc" if Lan==7 | Lan==10 | Lan==13 | Lan==14 | Lan==6 | Lan==8, replace sum(log) keep( Alder Female AntFlyttTot AntFlyttKommun LoneInk mths employed Akassa Children invand married)
	outreg2 using "TableA2Remainingmunics.doc" if kommun!=1280 & Lan!=7 & Lan!=10 & Lan!=13 & Lan!=14 & Lan!=6 & Lan!=8, replace sum(log) keep( Alder Female AntFlyttTot AntFlyttKommun LoneInk mths employed Akassa Children invand married)
	}


	************
	* Table B3 *
	************
	{
	clear all
	use "$path_base\RegSamp", clear

	foreach xvar of varlist DKtotwage Totwage SEKtotwage  {
	replace `xvar'=`xvar'/1000
	}
			
	destring Akassa, force replace
	gen work=(SEKwork==1 | DKwork==1)
	gen UI=(Akassa>0 & Akassa!=.)
	gen worknoUI=(work==1 & UI==0)
	ren Alder Age
		
		foreach xvar of varlist DKwork SEKwork DKtotwage Totwage SEKtotwage work worknoUI UI {
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tabx_allDeltas.csv", replace keep(Y1997 Y1998 Y1999 Y2000 Y2001 Y2002 Y2003 Y2004 Y2005 Y2006 Y2007 Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) ///
			}
	}


	************
	* Table B4 *
	************	
	{
		* Opening the data 
		use "$path_base\RegSamp", clear

		* Age indicator 
		ren Alder age
		gen AG=0
		replace AG=1 if age<30
		replace AG=2 if age<50 & AG!=1
		replace AG=3 if AG==0
		replace Totwage=Totwage/1000
		eststo clear
		
		foreach xvar of varlist Totwage DKwork {
		eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if AG==1, a(kommun) cluster(kommun)
			estadd ysumm
			esttab using "Table2.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)  
			
		eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if AG==2, a(kommun) cluster(kommun)
			estadd ysumm
			esttab using "Table2.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)  
			
		eststo: xi: areg `xvar' Y1997-Y2008 i.year i.Treat i.FodelseAr if AG==3, a(kommun) cluster(kommun)
			estadd ysumm
			esttab using "Table2.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			}
			

		* Fully-interacted models to see if coefficients are significantly different from one another
		* Opening the data 
		use "$path_base\RegSamp", clear

		* Age indicator 
		ren Alder age
		gen AG=0
		replace AG=1 if age<30
		replace AG=2 if age<50 & AG!=1
		replace AG=3 if AG==0
		replace Totwage=Totwage/1000
		eststo clear
		
		* Interaction variables 
		forvalues i=1997(1)2008 {
		gen YY`i'=Y`i' if AG==1
		gen OY`i'=Y`i' if AG==3
		replace YY`i'=0 if AG!=1
		replace OY`i'=0 if AG!=3
		}
			
		destring FodelseAr, force replace
		gen Yyear=year if AG==1
		gen Ykommun=kommun if AG==1
		gen YTreat=Treat if AG==1
		gen Oyear=year if AG==3
		gen Okommun=kommun if AG==3
		gen OTreat=Treat if AG==3
		gen YFodelseAr=FodelseAr if AG==1
		gen OFodelseAr=FodelseAr if AG==3
			
		replace Yyear=0 if AG!=1
		replace Ykommun=0 if AG!=1
		replace YTreat=0 if AG!=1
		replace Oyear=0 if AG!=3
		replace Okommun=0 if AG!=3
		replace OTreat=0 if AG!=3
		replace OFodelseAr=0 if AG!=3
		replace YFodelseAr=0 if AG!=1
		
		gen Y=(AG==1)
		gen O=(AG==3)
			
		* Regressions
			preserve
			drop if AG==3
			foreach xvar of varlist DKwork Totwage {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 YY1997-YY2008, a(Y year Yyear kommun Ykommun Treat YTreat FodelseAr YFodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2_AGESpec_AB.csv", replace keep(Y2008 YY2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}
			restore
			
			preserve
			drop if AG==2
			drop YY1997 YY1998 YY1999 YY2000 YY2001 YY2002 YY2003 YY2004 YY2005 YY2006 YY2007 YY2008
			foreach xvar of varlist DKwork Totwage {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 OY1997-OY2008, a(O year Oyear kommun Okommun Treat OTreat FodelseAr OFodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2_AGESpec_AC.csv", replace keep(Y2008 OY2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}
			restore
			
			preserve
			drop if AG==1
			foreach xvar of varlist DKwork Totwage {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 OY1997-OY2008, a(O year Oyear kommun Okommun Treat OTreat FodelseAr OFodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "Tab2_AGESpec_BC.csv", replace keep(Y2008 OY2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}
			restore
			
	}


	************
	* Table B5 *
	************	
	{
	use "$path_base\RegSamp", clear

	foreach xvar of varlist DKtotwage Totwage SEKtotwage  {
	replace `xvar'=`xvar'/1000
	}
					
	destring Akassa, force replace
	gen work=(SEKwork==1 | DKwork==1)
	gen UI=(Akassa>0 & Akassa!=.)
	gen worknoUI=(work==1 & UI==0)	

		gen Relative_time=year-2000
		gen Relative_timeT=Relative_time*Treat
		eststo clear

		foreach xvar of varlist DKwork SEKwork DKtotwage Totwage SEKtotwage work worknoUI UI {
		eststo: xi: reghdfe `xvar' Treat Relative_time Relative_timeT if year<2000, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
		replace `xvar'=`xvar'-(_b[Relative_timeT]*Relative_time) if Treat==1
		eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
		esttab using "TabA5.csv", replace keep(Y2008) label nonumber ///
		stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
		}
	}

		
	************
	* Table B6 *
	************	
	{
	clear all
	use "$path_base\RegSamp", clear

	foreach xvar of varlist Totwage  {
	replace `xvar'=`xvar'/10
	}

	bysort P0950_LopNr_PersonNr: egen DKyears=sum(DKwork)
	keep if DKyears==0

		foreach xvar of varlist Totwage SEKwork {
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(kommun Treat year FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "TabA6_stayers_Alt.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) ///
			}
	}
		
		
	************
	* Table B7 *
	************
	{
		* Pooled
		{
		eststo clear
			use "$path_base\RegSamp3", clear
			gen live99L=Lan if year==1999
			bysort P0950_LopNr_PersonNr: egen insampL=max(live99L)
			keep if Lan==12 | Lan==7 | Lan==10 | Lan==13 | Lan==6 | Lan==8
			drop if Lan==12 & kommun!=1280	
			gen age99=Alder-(year-1999) 
			gen Age=Alder
		
			foreach xvar of varlist DKwork {
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
			esttab using "TabA7.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if ((Lan==insampL & age99>18) | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
			esttab using "TabA7.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			}	
				
			foreach xvar of varlist Totwage  {
			replace `xvar'=`xvar'/1000
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
			esttab using "TabA7.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if ((Lan==insampL & age99>18) | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
			esttab using "TabA7.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			}	
		}
		
		* Males
		{
		eststo clear
			use "$path_base\RegSamp3", clear
			gen live99L=Lan if year==1999
			bysort P0950_LopNr_PersonNr: egen insampL=max(live99L)
			keep if Lan==12 | Lan==7 | Lan==10 | Lan==13 | Lan==6 | Lan==8
			drop if Lan==12 & kommun!=1280	
			gen age99=Alder-(year-1999) 
			gen Age=Alder

		keep if Female==0
			foreach xvar of varlist DKwork {
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7M.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
			esttab using "TabA7M.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if ((Lan==insampL & age99>18) | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
			esttab using "TabA7M.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7M.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}	
			foreach xvar of varlist Totwage  {
			replace `xvar'=`xvar'/1000
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7M.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
			esttab using "TabA7M.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if ((Lan==insampL & age99>18) | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
			esttab using "TabA7M.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7M.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}	
		}
		
		* Females
		{
		eststo clear
			use "$path_base\RegSamp3", clear
			gen live99L=Lan if year==1999
			bysort P0950_LopNr_PersonNr: egen insampL=max(live99L)
			keep if Lan==12 | Lan==7 | Lan==10 | Lan==13 | Lan==6 | Lan==8
			drop if Lan==12 & kommun!=1280	
			gen age99=Alder-(year-1999) 
			gen Age=Alder

		*sample 50
		keep if Female==1
			foreach xvar of varlist DKwork {
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7F.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
			esttab using "TabA7F.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if ((Lan==insampL & age99>18) | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
			esttab using "TabA7F.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7F.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}	
				
			foreach xvar of varlist Totwage  {
			replace `xvar'=`xvar'/1000
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7F.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008 Age Female Immigrant married child Mths, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) 
			esttab using "TabA7F.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if ((Lan==insampL & age99>18) | age99<18) & Immigrant==0, a(year Treat kommun FodelseAr) cluster(kommun) tol(1e-6) // No internal migrants (but young people allowed)
			esttab using "TabA7F.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year Treat kommun P0950_LopNr_PersonNr FodelseAr) cluster(kommun) tol(1e-6)
			esttab using "TabA7F.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}	
		}
	}


	************
	* Table B8 *
	************ 
	{	
	use "$path_base\RegSamp", clear 
	keep if Alder>24	// Same age restriction as in main analysis when looking at education to ensure majority has completed. 
		
		foreach xvar of varlist Totwage  {
		replace `xvar'=`xvar'/1000
		}
		
		forvalues i=1(1)8 {
		eststo clear
		foreach xvar of varlist DKwork Totwage {
			eststo: xi: reghdfe `xvar' Y1997-Y2008 if Female==0 & educ_specialization==`i', a(kommun year Treat FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "TabA8_`i'.csv", replace keep(Y2008) label nonumber stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			
			eststo: xi: reghdfe `xvar'  Y1997-Y2008  if Female==1 & educ_specialization==`i', a(kommun year Treat FodelseAr) tol(1e-6) cluster(kommun)
			estadd ysumm 
			esttab using "TabA8_`i'.csv", replace keep(Y2008) label nonumber stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}
		}
		
		
		* Examining if the gender coefficients are significantly different from each other through fully interacted models 
		
		* Opening the data 
		use "$path_base\RegSamp", clear
		keep if Alder>24
		compress 

			* Generating interaction variables 
				forvalues i=1997(1)2008 {
				gen MALEY`i'=Y`i' if Female==0
				replace MALEY`i'=0 if Female==1
				}
				destring FodelseAr, force replace
				gen MALEyear=year if Female==0
				gen MALEkommun=kommun if Female==0
				gen MALETreat=Treat if Female==0
				gen MALEFodelseAr=FodelseAr if Female==0
				
				replace MALEyear=0 if Female==1
				replace MALEkommun=0 if Female==1
				replace MALETreat=0 if Female==1
				replace MALEFodelseAr=0 if Female==1

			foreach xvar of varlist Totwage  {
			replace `xvar'=`xvar'/1000
			}
			
			forvalues i=1(1)8 {
			eststo clear
			foreach xvar of varlist DKwork Totwage {
				eststo: xi: reghdfe `xvar' Y1997-Y2008 MALEY1997-MALEY2008 if educ_specialization==`i', a( Female MALEkommun MALEyear MALETreat kommun year Treat FodelseAr MALEFodelseAr) tol(1e-6) cluster(kommun)
				estadd ysumm 
				esttab using "TabA8_`i'_EdSpecMale.csv", replace keep(Y2008 MALEY2008) label nonumber stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}
			}
			}
				 
			
	************
	* Table B9 *
	************		
	* Not estimated in Stata - Scaling excercise. 
			
			
	*************
	* Table B10 *
	*************	
	{
	* Opening the data 
	use "$path_base\RegSamp3", clear

	* Keeping new analysis sample
	keep if kommun==1280 |  kommun==1233 | kommun==1263 | kommun==1287 | kommun==1231 | kommun==1230  | kommun==1261  | kommun==1262  | kommun==1281  | Lan==7 | Lan==10 | Lan==13 | Lan==14 | Lan==6 | Lan==8

	* Scaling wage variables 
	foreach xvar of varlist DKtotwage Totwage SEKtotwage  {
	replace `xvar'=`xvar'/1000
	}
		
	* Constructing supplemental outcome variables 
	destring Akassa, force replace
	gen work=(SEKwork==1 | DKwork==1)
	gen UI=(Akassa>0 & Akassa!=.)
	gen worknoUI=(work==1 & UI==0)
	ren Alder Age

	* Adjusting treatment to include the expanded treatment group municipalities
	replace Treat=1 if kommun==1233 | kommun==1263 | kommun==1287 | kommun==1231 | kommun==1230  | kommun==1261  | kommun==1262  | kommun==1281
	drop Y1997-Y2008

		gen Y1997 = (year==1997 & Treat==1)
		gen Y1998 = (year==1998 & Treat==1)
		gen Y1999 = 0
		gen Y2000 = (year==2000 & Treat==1)
		gen Y2001 = (year==2001 & Treat==1)
		gen Y2002 = (year==2002 & Treat==1)
		gen Y2003 = (year==2003 & Treat==1)
		gen Y2004 = (year==2004 & Treat==1)
		gen Y2005 = (year==2005 & Treat==1)
		gen Y2006 = (year==2006 & Treat==1)
		gen Y2007 = (year==2007 & Treat==1)
		gen Y2008 = (year==2008 & Treat==1)

	* Estimating the regressions 	
	foreach xvar of varlist Totwage DKwork SEKwork DKtotwage SEKtotwage work worknoUI UI {
			qui: eststo: xi: reghdfe `xvar' Y1997-Y2008, a(kommun year Treat FodelseAr) tol(1e-6) cluster(kommun)
			esttab using "TabB10.csv", replace keep(Y2008) label nonumber ///
			stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
			}
	}
			
			
	*************
	* Table B11 *
	*************
	{
		* Opening main data and appending earlier years 
		use "$path_base\RegSamp", clear
		append using "$path_base\Individ1995_1996", force

		* Defauls categories in regression
		char year[omit] 1999
		char kommun[omit] 1280
		
		* Dropping irrelevant variables for speed	
		keep Y* SEKwork SEKtotwage Treat year kommun FodelseAr age 
		destring FodelseLan, force replace
		replace SEKtotwage=SEKtotwage/1000
		
		* Keeping estimation sample
		keep if Lan==12 | Lan==7 | Lan==10 | Lan==13 | Lan==6 | Lan==8
		drop if Lan==12 & kommun!=1280
		
		* Generating treatment variables 
		gen Relative_time=year-2000
		gen Relative_timeT=Relative_time*Treat

		* Running the regressions 
		eststo clear
		foreach xvar of varlist SEKwork SEKtotwage {
		eststo: xi: reghdfe `xvar' Treat Relative_time Relative_timeT if year<2000, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
		replace `xvar'=`xvar'-(_b[Relative_timeT]*Relative_time) if Treat==1
		eststo: xi: reghdfe `xvar' Y1997-Y2008, a(year kommun Treat FodelseAr) tol(1e-6) cluster(kommun)
		esttab using "TabA11.csv", replace keep(Y2008) label nonumber ///
		stats(ymean N) b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) 
	}
	}	



log close
